public enum TestEnum {  //默认继承于Enum抽象类
    RED("RED",1),BLACK("BLACK",10),GREEN("GREEN",8),
    WHITE("WHITE",90); //4个枚举对象

    private String color;
    private int ori;

    //默认是私有的
    TestEnum(String color,int ori){
        this.color = color;
        this.ori = ori;
    }

    //用法2
    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();  //values()：以数组形式返回枚举类型的所有成员
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i] + "ori:" +testEnums[i].ordinal()); //ordinal()：获取枚举成员的索引位置
        }
        System.out.println();
        System.out.println("=================");

        TestEnum testEnum2 = TestEnum.valueOf("WHITE"); //valueOf: 将普通字符串转换为枚举实例
        System.out.println(testEnum2);
        System.out.println("================");

        System.out.println(RED.compareTo(WHITE)); //compareTo() 比较两个枚举成员在定义时的顺序
        System.out.println(WHITE.compareTo(RED));
    }

    //用法1
    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum){
            case RED:
                System.out.println("红色");
                break;
            case GREEN:
                System.out.println("绿色");
                break;
            case BLACK:
                System.out.println("黑色");
                break;
            case WHITE:
                System.out.println("白色");
                break;
        }
    }
}
